#include "inputtest.h"

bool InputTest::run() {
    short count=0;

    if (!InputTest::constructorTest())
        std::cout << "ERROR " << ++count << " InputTest::constructorTest() faild!" << std::endl;
    if (!InputTest::getDimensionTest())
        std::cout << "ERROR " << ++count << " InputTest::getDimensionTest() faild!" << std::endl;
    if (!InputTest::createPrimeInputTest())
        std::cout << "ERROR " << ++count << " InputTest::createPrimeInputTest() faild!" << std::endl;
    if (!InputTest::getSizeTest())
        std::cout << "ERROR " << ++count << " InputTest::getSizeTest() faild!" << std::endl;
    if (!InputTest::inputIteratorTest())
        std::cout << "ERROR " << ++count << " InputTest::inputIteratorTest() faild!" << std::endl;
    if (!InputTest::importFromTextfileTest())
        std::cout << "ERROR " << ++count << " InputTest::importFromTextfileTest() faild!" << std::endl;
    return count==0;
}

bool InputTest::constructorTest() {
    Input* input = new Input();
    delete input;
    input = new Input();
    input->createPrimeInput(10);
    delete input;
    input = new Input();
    input->createPrimeInput(1);
    delete input;
    input = new Input();
    input->createPrimeInput(200);
    delete input;
    return true;;
}

bool InputTest::getDimensionTest() {
    Input* input = new Input();
    input->createPrimeInput(2);
    assert(input->getDimension()==1);
    delete input;
    return true;
}

bool InputTest::createPrimeInputTest() {
    Input* input = new Input();
    input->createPrimeInput(2);
    assert(input->getDimension()==1);
    InputIterator& inputIterator = input->getNewIterator();
    assert(inputIterator.getNext().getValue()==2);
    assert(inputIterator.getNext().getValue()==3);
    assert(!inputIterator.hasNext());
    delete &inputIterator;
    delete input;
    Input* input2 = new Input();
    input2->createPrimeInput(25);
    assert(input2->getDimension()==1);
    InputIterator& inputIterator2 = input2->getNewIterator();
    assert(inputIterator2.getNext().getValue()==2);
    assert(inputIterator2.getNext().getValue()==3);
    assert(inputIterator2.getNext().getValue()==5);
    assert(inputIterator2.getNext().getValue()==7);
    assert(inputIterator2.getNext().getValue()==11);
    assert(inputIterator2.getNext().getValue()==13);
    assert(inputIterator2.getNext().getValue()==17);
    assert(inputIterator2.getNext().getValue()==19);
    assert(inputIterator2.getNext().getValue()==23);
    assert(inputIterator2.getNext().getValue()==29);
    assert(inputIterator2.getNext().getValue()==31);
    assert(inputIterator2.getNext().getValue()==37);
    assert(inputIterator2.getNext().getValue()==41);
    assert(inputIterator2.getNext().getValue()==43);
    assert(inputIterator2.getNext().getValue()==47);
    assert(inputIterator2.getNext().getValue()==53);
    assert(inputIterator2.getNext().getValue()==59);
    assert(inputIterator2.getNext().getValue()==61);
    assert(inputIterator2.getNext().getValue()==67);
    assert(inputIterator2.getNext().getValue()==71);
    assert(inputIterator2.getNext().getValue()==73);
    assert(inputIterator2.getNext().getValue()==79);
    assert(inputIterator2.getNext().getValue()==83);
    assert(inputIterator2.getNext().getValue()==89);
    assert(inputIterator2.getNext().getValue()==97);
    assert(!inputIterator2.hasNext());
    delete &inputIterator2;
    delete input2;
    return true;
}

bool InputTest::getSizeTest() {
    Input* input = new Input();
    input->createPrimeInput(2);
    assert(input->getDimension()==1);
    assert(input->getSize()==2);
    delete input;
    return true;
}

bool InputTest::inputIteratorTest() {
    Input* input = new Input();
    input->createPrimeInput(3);
    InputIterator& inputIterator = input->getNewIterator();
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==2);
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==3);
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==5);
    assert(!inputIterator.hasNext());
    inputIterator.reset();
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==2);
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==3);
    assert(inputIterator.hasNext());
    assert(inputIterator.getNext().getValue()==5);
    assert(!inputIterator.hasNext());
    delete &inputIterator;
    delete input;
    return true;
}

bool InputTest::importFromTextfileTest() {
    Input* input = new Input();
    char fileName[] = "inputTest";
    assert(input->importFromTextfile(fileName));
    assert(input->getDimension()==1);
    InputIterator& iterator=input->getNewIterator();
    assert(iterator.getNext().getValue()==2);
    assert(iterator.getNext().getValue()==3.3);
    assert(iterator.getNext().getValue()==5);
    assert(iterator.getNext().getValue()==7);
    assert(iterator.getNext().getValue()==11.12);
    assert(iterator.getNext().getValue()==13);
    assert(iterator.getNext().getValue()==17);
    assert(iterator.getNext().getValue()==23);
    assert(iterator.getNext().getValue()==29);
    assert(!iterator.hasNext());
    iterator.reset();
    assert(iterator.getNext().getPositionArray()[0]==1);
    assert(iterator.getNext().getPositionArray()[0]==2.2);
    assert(iterator.getNext().getPositionArray()[0]==3);
    assert(iterator.getNext().getPositionArray()[0]==4);
    assert(iterator.getNext().getPositionArray()[0]==5.6);
    assert(iterator.getNext().getPositionArray()[0]==6);
    assert(iterator.getNext().getPositionArray()[0]==7);
    assert(iterator.getNext().getPositionArray()[0]==8);
    assert(iterator.getNext().getPositionArray()[0]==9);
    assert(!iterator.hasNext());

    delete input;
    delete &iterator;
    return true;
}
